<%@ page contentType="text/html; charset=UTF-8" language="java"%>
<%@ include file="/commons/taglibs.jsp"%>
<%@ page import="java.util.List" %>
<%@ page import="cn.com.pxto.model.Dic" %>
<%@ page import="cn.com.pxto.global.varables.LogonInfo" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>sidebar</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">

<link href="styles/css/global.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="commons/dojo.js"></script>
<script type="text/javascript">
	dojo.require("dojo.lang.*");
	dojo.require("dojo.event.*");
	dojo.require("dojo.widget.*");
	dojo.require("dojo.widget.Tree");
	dojo.require("dojo.widget.TreeSelector");

	function Subscriber(){
	    this.update = function(message) {
			//parent.frames("main").location.href=message.node.object;
			parent.frames["main"].location.href=message.node.object;
			//parent.getElementByName("main").location.href=message.node.object;
			//parent.document.getElementById("main").location=message.node.object;
	    };
	}
	//绑定事件
	var scriber = new Subscriber();
	var nodeSelection = dojo.event.topic.getTopic("nodeSelected");
	nodeSelection.subscribe(scriber, "update");
</script>
<%
List list = (List)request.getAttribute("funcs");  //declare
LogonInfo logoninfo = (LogonInfo)request.getSession().getAttribute("logonInfo");
%>
</head>
<body bgcolor="#DEF7FF">
<table align="left" bgcolor="#DEF7FF" width="100%" height="100%">
      <tr>
		<td valign="top">
		<div dojoType="TreeSelector" eventNames="select:nodeSelected"
			widgetId="treeSelector"></div>
		<div id="funcs" dojoType="Tree" showGrid="false" style="font-size:20pt"
			selector="treeSelector" expandLevel="3"><%
			//当前父id临时列表
			java.util.ArrayList tempPIDList = new java.util.ArrayList();
			for (int i=0;i<list.size();i++){
				Dic thisDic = (Dic)list.get(i);
				//判断是否是SIDEBAR的菜单
				if (thisDic.getFunType()!=null&&thisDic.getFunType().equals("SIDEBAR")){
//					判断权限
					if (logoninfo.canAccess(thisDic.getId().intValue())){
						if (thisDic.getDefValue().length()!=3){ //第一层不用显示
							out.println("<div dojoType=\"TreeNode\" title=\""+thisDic.getName()+"\"object=\""+
									(thisDic.getMemo().length()>3?thisDic.getMemo():"javacsript:null")+"\">");
							//判断是否已经到了末尾
							if (i==(list.size()-1)){
								out.println("</div>");
							}else{
								//这一层如果包含子节点，那么就不输出</div>，并把父id添加到列表中
								Dic nextDic = null;
								for (int j=i+1;j<list.size();j++){
								 	nextDic = (Dic)list.get(j);
								 	if (thisDic.getFunType()!=null&&nextDic.getFunType().equals("SIDEBAR")){
								 		if (logoninfo.canAccess(nextDic.getId().intValue())){
								 			break;
								 		}
								 	}
								}
								//没有子菜单
								if (nextDic==null){
									out.println("</div>");//关闭父节点的div
								}
								if (nextDic.getDefValue().startsWith(thisDic.getDefValue())) { //下一个节点是当前节点的子节点
									tempPIDList.add(thisDic);  //将当前节点添加到父节点临时列表
								}
								else{  //下一个节点不是当前节点的子节点
									out.println("</div>");  //封闭当前节点的div
									//判断下一个节点是否是父节点的子节点
									for (int j=tempPIDList.size()-1;j>=0;j--){  //父节点列表反向的获取，看是否该关闭这个父节点<div>
										Dic pDic = (Dic)tempPIDList.get(j);
										if (!nextDic.getDefValue().startsWith(pDic.getDefValue())){  //如果下一个节点不是父节点的子节点
											out.println("</div>");//关闭父节点的div
											tempPIDList.remove(j);
										}
									}
								}
							}				
						}
					}
				}
			}
			%>
			<div dojoType="TreeNode" title="注销登出" object="javascript:parent.logout();">
			</div>
		</div>		
		</td>
	</tr>
</table>
</body>
</html>